package com.danawa.watcher.common;

import java.util.HashMap;

import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@RequestMapping("/errors")
public class ErrorController {
	
	
	
	@RequestMapping("/400")
	public String handle400(	ModelMap model) {
		HashMap<String, Object> errorMap = new HashMap<String, Object>();
		errorMap.put("code", HttpServletResponse.SC_BAD_REQUEST);
		errorMap.put("msg", "Request Error or Parameter Error");

		model.addAttribute("errorMap",errorMap);
		return "error/error";
	}
	
	@RequestMapping("/403")
	public String handle403(	ModelMap model) {
		
		HashMap<String, Object> errorMap = new HashMap<String, Object>();
		errorMap.put("code", HttpServletResponse.SC_FORBIDDEN);
		errorMap.put("msg", "Forbidden Error");

		model.addAttribute("errorMap",errorMap);
		return "error/error";
	}

	@RequestMapping("/404")
	public String handle404(	ModelMap model) {
		HashMap<String, Object> errorMap = new HashMap<String, Object>();
		errorMap.put("code", HttpServletResponse.SC_NOT_FOUND);
		errorMap.put("msg", "Not Found Resource");
		model.addAttribute("errorMap",errorMap);
		return "error/error";
	}
	
	@RequestMapping("/405")
	public String handle405(	ModelMap model) {
		HashMap<String, Object> errorMap = new HashMap<String, Object>();
		errorMap.put("code", HttpServletResponse.SC_METHOD_NOT_ALLOWED);
		errorMap.put("msg", "Method not allowed");
		model.addAttribute("errorMap",errorMap);
		return "error/error";
	}


	@RequestMapping("/500")
	public String handle500(
			ModelMap model) {
		HashMap<String, Object> errorMap = new HashMap<String, Object>();
		errorMap.put("code", HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
		errorMap.put("msg", "500 Internal Server Error");
		model.addAttribute("errorMap",errorMap);
		return "error/error";
	}
}
